package com.campus.delivery.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.delivery.entity.DeliveryUser;
import com.campus.delivery.mapper.DeliveryUserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 配送员用户表 服务实现类
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-05-12
 */
@Service
public class DeliveryUserService extends ServiceImpl<DeliveryUserMapper, DeliveryUser> {

    /**
     * 更新配送员昵称和头像
     * @param id 配送员ID
     * @param nickname 昵称
     * @param avatar 头像
     * @return 更新后的DeliveryUser对象
     */
    public DeliveryUser updateNicknameAndAvatar(Integer id, String nickname, String avatar) {
        DeliveryUser user = this.getById(id);
        if (user == null) {
            throw new RuntimeException("配送员不存在");
        }
        if(StringUtils.isNotBlank(nickname)){
            user.setNickname(nickname);
        }
        if (StringUtils.isNotBlank(avatar)){
            user.setAvatar(avatar);
        }
        this.updateById(user);
        return user;
    }
}
